<head>
    <include file="public@head" title="权限组" keywords="后台管理系统"/>
</head>

<body>
<div class="layui-card">
    <div class="layui-card-body">
        <form method="post" action="{:url('setRules')}" class="layui-form">
            <input type="hidden" name="id" value="{$info.id}">
            <div class="layui-form-item">
                <table class="layui-table">
                    <colgroup>
                        <col width="80">
                        <col width="200">
                        <col>
                    </colgroup>
                    <thead>
                    <tr>
                        <th>选择</th>
                        <th>名称</th>
                        <th>URL</th>
                    </tr>
                    </thead>
                    <tbody id="tbody">
                    <volist name="$rules" id="v">
                        <tr>
                            <td><input type="checkbox" lay-filter="rules" data-pid="{$v.pid}" name="rules[]" value="{$v['id']}" <if condition="in_array($v['id'], $info['res'])"> checked</if> >
                            </td>
                            <td>{$v['title']}</td>
                            <td>{$v['name']}</td>
                        </tr>
                    </volist>
                    </tbody>
                </table>
            </div>

            <div class="layui-form-item text-center">
                <button type="submit" class="layui-btn" lay-submit lay-filter="general">提交</button>
            </div>
        </form>
    </div>
</div>
<include file="public@scripts"/>
<script>
    form.on('checkbox(rules)', function (data) {
        var pid = data.value;
        if (data.elem.checked) {
            $("input[type=checkbox]").each(function (i) {
                var text = $(this).data('pid');
                if (text == pid) {
                    $(this).prop("checked", true);
                    form.render('checkbox');
                }
            });
        } else {
            $("input[type=checkbox]").each(function (i) {
                var text = $(this).data('pid');
                if (text == pid) {
                    $(this).prop("checked", false);
                    form.render('checkbox');
                }
            });
        }
    });
</script>
</body>
